package com.woniuxy.oldmanapi.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.oldmanapi.entity.Medicine;
import com.woniuxy.oldmanapi.mapper.MedicineMapper;
import com.woniuxy.oldmanapi.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MedicineService {
    @Autowired
    MedicineMapper medicineMapper;


    //@Cacheable(value = "medicine", key="#root.targetClass+#root.methodName+#root.args[0]+#root.args[1]+#root.args[2]")
    public PageInfo<Medicine> findMedicineByCons(String drugname, int size, int now) {
        PageHelper.startPage(now,size);
        List<Medicine> list=medicineMapper.selectDrugsByCons(drugname);
        return  new PageInfo<>(list);
    }

    //@CacheEvict(value = "medicine",allEntries = true)
    public void addMedicine(Medicine medicine) {
        medicineMapper.insert(medicine);
    }

   // @CacheEvict(value = "medicine",allEntries = true)
    public void modifyMedicine(Medicine medicine) {
        medicineMapper.updateByPrimaryKey(medicine);
    }

    //@CacheEvict(value = "medicine",allEntries = true)
    public void removeMedicineById(int mid) {
        medicineMapper.deleteByPrimaryKey(mid);
    }

    //@Cacheable(value = "medicine", key="#root.targetClass+#root.methodName")
    public List<Medicine> findAllMedicine() {
      return   medicineMapper.selectAll();
    }
}
